from selenium.webdriver.common.by import By

from wewrok_app_po.Base.wework_app import WeWorkApp


class ClockPage(WeWorkApp):
    _OUT = By.XPATH,'//*[contains(@text,"次外出")]'
    _CLOCK = '外出打卡'
    _CLOCK_OUT = By.XPATH,"//*[@text='外出打卡']"
    _TEXT = '外出打卡成功'
    _SUCCESS = By.XPATH,"//*[@text='外出打卡成功']"

    def click_out_clock(self):
        # 等待外出打开出现
        ctrl = self.wait_for_text(self.driver,self._CLOCK)

        if ctrl == True:
            self.find_and_click(*self._CLOCK_OUT)
        # 等待次外出出现
        ctrl = self.wait_for_click(self.driver,*self._OUT)
        if ctrl == True:
            self.find_and_click(*self._OUT)
        ctrl = self.wait_for_text(self.driver,self._TEXT)
        if ctrl == True:
            res = self.find_and_text(*self._SUCCESS)
            return res

